package com.gui.service;

import com.gui.DTO.QuestionDTO;
import com.gui.mapper.QuestionMapper;
import com.gui.mapper.UserMapper;
import com.gui.model.Question;
import com.gui.model.User;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * QuestionSerice
 *
 * @author guigu
 * @QQ 1170258867
 * @date 2020/6/11
 * @description
 */
@Service
public class QuestionSerice {

    @Autowired
    private QuestionMapper questionMapper;
    @Autowired
    private UserMapper userMapper;

    public QuestionDTO getQuestionDTO(int id){
        Question oneQuestion = questionMapper.getOneQuestion(id);
        User user = userMapper.selectById(oneQuestion.getCreator());
        QuestionDTO questionDTO = new QuestionDTO();
        BeanUtils.copyProperties(oneQuestion,questionDTO);
        questionDTO.setUser(user);
        return questionDTO;
    }
}
